//
//  SexInPutView.m
//  夺宝吧
//
//  Created by xiaocai on 15/7/21.
//  Copyright (c) 2015年 FangYuan. All rights reserved.
//

#import "SexInPutView.h"

@interface SexInPutView ()<UIPickerViewDataSource,UIPickerViewDelegate>
{
    __weak IBOutlet UIButton *ensureBtn;
    __weak IBOutlet UIButton *cancelBtn;
    
    __weak IBOutlet UIPickerView *sexPicker;
    NSArray *_data;
    NSString *_currentSex;
}
@end
@implementation SexInPutView
- (void)morenzhi:(NSString *)sex
{
    _currentSex = sex;
    NSInteger index = 1;
    for (NSString *s in _data) {
        if ([s isEqualToString:sex]) {
            index = [_data indexOfObject:s];
        }
    }
     [sexPicker selectRow:index inComponent:0 animated:NO];
}

- (void)awakeFromNib
{
    ensureBtn.layer.cornerRadius = 2;
    cancelBtn.layer.cornerRadius = 2;
    ensureBtn.layer.borderWidth = 1;
    cancelBtn.layer.borderWidth = 1;
    ensureBtn.layer.masksToBounds = YES;
    cancelBtn.layer.masksToBounds = YES;
    ensureBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    cancelBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    ensureBtn.backgroundColor = QBB_RED_COLOR;
    self.layer.borderWidth = 1;
    self.layer.borderColor = [UIColor blackColor].CGColor;
    self.layer.cornerRadius = 5;
    self.layer.masksToBounds = YES;
    
    sexPicker.dataSource = self;
    sexPicker.delegate =  self;
    _data = @[@"女",@"男",@"保密"];
    [sexPicker reloadAllComponents];
}

- (IBAction)ensurebtnOnClick:(id)sender {
    [self.father changeSex:_currentSex];
    [self removeFromSuperview];
}

- (IBAction)cancelBtnOnClick:(id)sender {
    [self.father removeZheZhao];
    [self removeFromSuperview];
}
#pragma mark pickerview function

/* return cor of pickerview*/
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
/*return row number*/
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [_data count];
}

/*return component row str*/
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [_data objectAtIndex:row];
}

/*choose com is component,row's function*/
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    // NSLog(@"font %@ is selected.",row);
    NSString *fontname=[_data objectAtIndex:row];
    _currentSex = fontname;
    
}
@end
